<?php

namespace App\Kuafu\Mybank\Service;

use App\Kuafu\Base\Service\BaseService;
use App\Kuafu\Mybank\Model\MybankOrderWithholdRecordModel;
use App\Kuafu\Mybank\Model\MybankOrderWithholdRefundRecordModel;

class MybankOrderWithholdRefundRecordService extends BaseService
{

    /***
     * 获取夸父支付退款信息
     *
     * @param array $ids
     * @return array
     */
    public static function getKfPayRefundInfoByIds(array $ids): array
    {
        if (empty($ids)) {
            return [];
        }
        $list = MybankOrderWithholdRefundRecordModel::query()
                                                    ->with("myBankOrderWithholdRecordRel")
                                                    ->whereIn('id', $ids)
                                                    ->get();


        $newArrays = [];
        if (!empty($list)) {
            foreach ($list as $item) {
                $outTradeNo = 0;
                $shopId     = 0;

                if (!empty($item['myBankOrderWithholdRecordRel'])) {
                    $outTradeNo = $item['myBankOrderWithholdRecordRel']['outTradeNo'];

                    $list = MybankOrderWithholdRecordModel::query()
                                                          ->with("myPayStreamRel")
                                                          ->where('id', $item['myBankOrderWithholdRecordRel']['id'])
                                                          ->first();

                    $shopId = $list['myPayStreamRel']['shopId'] ?? 0;
                }
                $newArrays[$item['id']] = [
                    // 渠道号
                    'outTradeNo'   => $outTradeNo,
                    // 退款金额
                    'refundAmount' => $item['refundAmount'],
                    // shopId
                    'shopId'       => $shopId

                    // other ,需要啥自己加
                ];
            }
        }
        return $newArrays;
    }


}